import 'package:buy_flutter/common/Application.dart';
import 'package:buy_flutter/common/sp/UserSharePreference.dart';
import 'package:buy_flutter/net/net_config.dart';
import 'package:buy_flutter/router/router_utils.dart';
import 'package:buy_flutter/router/routes.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class WelcomePage extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
            image: DecorationImage(
                image: AssetImage("assets/main/bg_splash_welcome.png"),
                fit: BoxFit.cover)),
        child: Stack(
          children: [
            Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    "小朋友你好",
                    style: TextStyle(
                        color: Color(0xff3fada9),
                        fontSize: 26,
                        fontWeight: FontWeight.bold),
                  ),
                  Container(
                    padding: EdgeInsets.only(top: 15, bottom: 15),
                    child: RichText(
                      textAlign: TextAlign.center,
                      text: TextSpan(children: [
                        TextSpan(
                          text: "欢迎来到",
                          style: TextStyle(
                            color: Color(0xff696969),
                            fontSize: 18,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        TextSpan(
                          text: "\n",
                        ),
                        TextSpan(
                          text: "GA",
                          style: TextStyle(
                            color: Color(0xffa92e37),
                            fontSize: 18,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        TextSpan(
                          text: "PSK",
                          style: TextStyle(
                            color: Color(0xff285f95),
                            fontSize: 18,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        TextSpan(
                          text: "  AI啟蒙學習系統",
                          style: TextStyle(
                            color: Color(0xff696969),
                            fontSize: 18,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ]),
                    ),
                  ),
                  ElevatedButton(
                    onPressed: () async {
                      String jwt = await UserSharePreference.getJwt();
                      print("jwt====>$jwt");
                      if (jwt != null && jwt.isNotEmpty) {
                        NetConfig.setJwt(jwt);
                        Application.router
                            .navigateTo(context, Routes.home, clearStack: true);
                      } else {
                        Application.router.navigateTo(context, Routes.login);
                      }
                    },
                    child: Text("登入"),
                    style: ButtonStyle(
                        backgroundColor:
                            MaterialStateProperty.all(Color(0xff3fada9)),
                        side: MaterialStateProperty.all(
                          BorderSide(width: 1, color: Color(0xff3fada9)),
                        ),
                        shape: MaterialStateProperty.all(
                          RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(20),
                          ),
                        ),
                        minimumSize: MaterialStateProperty.all(Size(150, 40)),
                        padding: MaterialStateProperty.all(EdgeInsets.all(0))),
                  ),
                  GestureDetector(
                    child: Padding(
                      padding: const EdgeInsets.all(15),
                      child: Text(
                        "建立账户",
                        style: TextStyle(
                            color: Color(0xff3fada9),
                            fontSize: 15,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                    onTap: () {
                      RouterUtils.goToNativePage(Routes.regist);
                    },
                  ),
                ],
              ),
            ),
            GestureDetector(
              child: Padding(
                padding: const EdgeInsets.only(bottom: 10.0),
                child: Align(
                  alignment: Alignment.bottomCenter,
                  child: RichText(
                    text: TextSpan(
                      children: [
                        TextSpan(
                            text: "登入或建立賬戶即表示你同意",
                            style: TextStyle(
                              color: Color(0xFF696969),
                              fontSize: 16,
                            )),
                        TextSpan(
                            text: "隱私政策及用戶協議",
                            style: TextStyle(
                              color: Color(0xFF3fada9),
                              fontSize: 16,
                            )),
                      ],
                    ),
                  ),
                ),
              ),
              onTap: () {
                RouterUtils.goToNativePage(Routes.h5Page,
                    {"h5Url": "https://www.gapsk.com/t-c"});
              },
            ),
          ],
        ),
      ),
    );
  }
}
